package ws

import (
	"github.com/gin-gonic/gin"
	"github.com/gofrs/uuid"
	"github.com/gorilla/websocket"
	"iot-base/auth/common/socket"
	"net/http"
)

// Ws 废弃.
func Ws(c *gin.Context) {
	conn, error := (&websocket.Upgrader{
		CheckOrigin: func(r *http.Request) bool { return true }}).Upgrade(c.Writer, c.Request, nil)
	if error != nil {
		http.NotFound(c.Writer, c.Request)
		return
	}
	uid, _ := uuid.NewV4()
	client := &socket.Client{
		ID:     uid.String(),
		Socket: conn,
		Send:   make(chan []byte),
	}
	socket.Hub.Register <- client
	go client.Read()
	go client.Write()
}
